package iec104;

public class CP56time2a {
	private short YY=0;
	private short MM=0;
	private short DD=0;
	private short hh=0;
	private short mm=0;
	private int msec=0;
	
	public short[] setCP56time2a(int yy,int m,int dd,int h,int mm0,int sec)
	{
		YY=(short) (yy&0x7F);
		MM=(short) (m&0x0F);
		DD=(short) (dd&0x1F);
		hh=(short) (h&0x1F);
		mm=(short) (mm0&0x3F);
		msec=sec&0xFFFF;
		
		short [] time=new short[7];
		time[0]=(short) (msec&0xFF);
		time[1]=(short) ((msec>>8)&0xFF);
		time[2]=(short) (mm&0xFF);
		time[3]=(short) (hh&0xFF);
		time[4]=(short) (DD&0xFF);
		time[5]=(short) (MM&0xFF);
		time[6]=(short) (YY&0xFF);
		return time;
	}
	void setTime(short []time,int len)
	{
		msec=time[0]|(time[1]<<8);
		mm=(short) (time[2]&0x3F);
		hh=(short) (time[3]&0x1F);
		DD=(short) (time[4]&0x1F);
		MM=(short) (time[5]&0x0F);
		YY=(short) (time[7]&0x7F);
	}
	public String tostring()
	{
		String timestr=new String("Time:");
		timestr=timestr.concat(Integer.toString(YY));
		timestr=timestr.concat("-"+Integer.toString(MM));
		timestr=timestr.concat("-"+Integer.toString(DD));
		timestr=timestr.concat(" "+Integer.toString(hh));
		timestr=timestr.concat(":"+Integer.toString(mm));
		timestr=timestr.concat(":"+Integer.toString(msec/1000));
		timestr=timestr.concat("."+Integer.toString(msec%1000));
		return timestr;
	}
}
